<template>
	<view class="content">
		<view class="header">
			<image src="../../../static/wallet.png" mode=""></image>
			<view class="all">
				<view class="name">总资产</view>
				<view class="bot" @click="goRecord">
					<text class="num">{{all_money}}</text>
					<text>提现记录</text>
					<u-icon name="arrow-right" color="#ffffff" size="28"></u-icon>
				</view>
			</view>
		</view>
		<view class="middle">
			<view class="title">
				<text>提现金额</text>
				<input v-model="money" class="right" type="text" value="" placeholder="请输入金额" />
			</view>
      <view class="" style="color: lightgray;">
        温馨提示：提现最小金额{{min_cash_money}}，最大金额{{max_cash_money}}，手续费{{svr_fee}}
      </view>
			<view class="text">提现方式：银行卡</view>
			<input v-model="name" class="item" type="text" value="" placeholder="请输入姓名" />
			<input v-model="bank" class="item" type="text" value="" placeholder="请输入开户行名称" />
			<input v-model="card_no" class="item" type="number" value="" placeholder="请输入银行卡号" />
		</view>
		<view class="footer" @click="submit">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				all_money: null,
				money: '',//金额
				name: '',
				bank: '',
				card_no: '',
        min_cash_money:'',
        max_cash_money:'',
        svr_fee:''
			}
		},
    onShow(){
      this.getUserInfo()
    },
    onLoad() {
      // this.getUserInfo()
      this.getdata()
    },
		methods: {
      async getUserInfo(){
      		let res = await this.$http.post('/api/user/userinfo');
          this.all_money=res.data.data.userinfo.money;
      		this.$store.commit('SAVE_USER',res.data.data.userinfo)
      },
      async getdata(){
        let res=await this.$http.post('/api/cash/getconf')
        this.min_cash_money=res.data.data.min_cash_money;
        this.max_cash_money=res.data.data.max_cash_money;
        this.svr_fee=res.data.data.svr_fee;
      },
			submit(){
				if(this.money == ''){
					this.$u.toast('请输入金额')
					return
				}
				if(this.name == ''){
					this.$u.toast('请输入姓名')
					return
				}
				if(this.bank == ''){
					this.$u.toast('请输入开户行')
					return
				}
				if(this.card_no == ''){
					this.$u.toast('请输入银行卡号')
					return
				}
        
        if(parseInt(this.money)<parseInt(this.min_cash_money) || parseInt(this.money)>parseInt(this.max_cash_money)){
        	this.$u.toast('提现最小金额'+this.min_cash_money+'，最大金额'+this.max_cash_money)
        	return
        }
				this.$http.post('/api/cash/add',{
					realname: this.name,
					bank: this.bank,
					card_no: this.card_no,
					money: this.money
				}).then(res => {
					console.log(res)
					this.$u.toast('提现成功');
					this.goRecord()
				})
			},
			goRecord(){
				uni.navigateTo({
					url:'/pages/componentB/record/record'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.content{
	background:rgba(248,248,248,1);
	min-height: 100vh;
	// padding-top: 30rpx;
	// box-sizing: border-box;
}
.header{
	width: 690rpx;
	height: 240rpx;
	margin: 30rpx auto;
	position: relative;
	border-radius: 10rpx;
	image{
		width: 690rpx;
		height: 240rpx;
	}
	.all{
		position: absolute;
		top: 0;
		left: 0;
		padding: 24rpx;
		box-sizing: border-box;
		width: 100%;
		.name{
			font-size:13px;
			font-family:PingFang SC;
			font-weight:400;
			color:rgba(255,255,255,1);
		}
		.bot{
			display: flex;
			justify-content: flex-start;
			align-items: center;
			margin-top: 63rpx;
			.num{
				font-size:36px;
				font-family:PingFang SC;
				font-weight:bold;
				color:rgba(255,255,255,1);
				flex: 1;
			}
			text{
				font-size:16px;
				font-family:PingFang SC;
				font-weight:400;
				color:rgba(255,255,255,1);
				margin-right: 10rpx;
			}
		}
	}
}
.middle{
	width: 100%;
	background-color: #FFFFFF;
	padding: 30rpx 30rpx;
	box-sizing: border-box;
	.title{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin-top: 10rpx;
		text{
			font-size:17px;
			font-family:PingFang SC;
			font-weight:bold;
			color:rgba(51,51,51,1);
			margin-right: 50rpx;
		}
		.right{
			border: none;
			outline: none;
			font-size:15px;
			font-family:PingFang SC;
			font-weight:bold;
			color:rgba(153,153,153,1);
		}
	}
	.text{
		margin-top: 50rpx;
		font-size:17px;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(51,51,51,1);
	}
	.item{
		display: block;
		width:690rpx;
		height:88rpx;
		background:rgba(248,248,248,1);
		border-radius:10px;
		border: none;
		font-size:13px;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(153,153,153,1);
		margin-top: 25rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
	}
}
.footer{
	width:535rpx;
	height:88rpx;
	background:rgba(63,195,119,1);
	border-radius:10px;
	margin: 66rpx auto;
	line-height: 88rpx;
	text-align: center;
	font-size:15px;
	font-family:PingFang SC;
	font-weight:bold;
	color:rgba(255,255,255,1);
}
</style>
